<?php 
$page=$_GET['page'];

$query=mysql_query("select * from promotion");
    $tongItems=mysql_num_rows($query);	
	if($tongItems%10==0){
	   $tongPage=$tongItems/10;
    }else{
	   $tongPage=(int)($tongItems/10+1);
   }
	
	$pageNow=$_GET['pageNow'];
	
	if($pageNow==""||$pageNow<1){
		$pageNow=1;
	}
	if($pageNow>$tongPage){
		$pageNow=$tongPage;
	}
	
	$start=($pageNow-1)*10;
	$num=10;
	
	
$sql="select * from promotion limit $start,$num";
$query=mysql_query($sql);

echo "<p align='center'>";
   
if($tongPage>1){
	
if($pageNow==1){
	    echo "|<<&nbsp;<";
	}else{
		echo "<a href='index.php?pageNow=1'> |<< </a> &nbsp;";
		echo "<a href='index.php?pageNow=".($pageNow-1)."'> < </a>";
    }

$i=$pageNow;
if($i<=$tongPage-5){
	while($i<$pageNow+5){
		if($i==$pageNow){
		    echo "&nbsp;&nbsp;<font color='red'><b><a href='index.php?pageNow=".$i."'>".$i."</a></b></font>&nbsp;&nbsp;";
		}else{
			echo "&nbsp;&nbsp;<a href='index.php?pageNow=".$i."'>".$i."</a>&nbsp;&nbsp;";
		}
		$i++;
	}
}else{
	if($tongPage<=5){
		$i=1;
		while($i<=$tongPage){
			if($i==$pageNow){
		    	echo "&nbsp;&nbsp;<font color='red'><b><a href='index.php?pageNow=".$i."'>".$i."</a></b></font>&nbsp;&nbsp;";
			}else{
				echo "&nbsp;&nbsp;<a href='index.php?pageNow=".$i."'>".$i."</a>&nbsp;&nbsp;";
			}
			$i++;
		}
	}else{
		$i=$tongPage-5;
		while($i<=$tongPage){
			if($i==$pageNow){
		    	echo "&nbsp;&nbsp;<font color='red'><b><a href='index.php?pageNow=".$i."'>".$i."</a></b></font>&nbsp;&nbsp;";
			}else{
				echo "&nbsp;&nbsp;<a href='index.php?pageNow=".$i."'>".$i."</a>&nbsp;&nbsp;";
			}
			$i++;
		}
	}
}

	if($pageNow==$tongPage){
		echo ">&nbsp;>>|";
	}else{
		echo "<a href='index.php?pageNow=".($pageNow+1)."'> > </a> &nbsp;";
		echo "<a href='index.php?pageNow=$tongPage'> >>| </a>";	
	} 
}

echo "</p>";


include("view/promotion.php");


?>